package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/26 17:22
 */
public class Title25 {

    class ListNode{
        int val;

        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode mergeTwoLists(ListNode l, ListNode r) {
        ListNode head = new ListNode(-1);
        ListNode cur = head;
        while (l != null && r != null) {
            if (l.val > r.val) {
                cur.next = r;
                r = r.next;
            }else{
                cur.next = l;
                l = l.next;
            }
            cur = cur.next;
        }
        if (l == null) {
            cur.next = r;
        }else{
            cur.next = l;
        }
        return head.next;
    }

    public static void main(String[] args) {

    }
}
